home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 109 / EnigmaAmiga109CD.iso / dalla rivista / host contacted / jikes.lha / jikes-1.11 / src / unparse.cpp < prev    next >
C/C++ Source or Header  |  1999-12-14  |  35KB  |  1,089 lines

  1. // $Id: unparse.cpp,v 1.5 1999/12/14 17:31:53 lord Exp $
  2. //
  3. // This software is subject to the terms of the IBM Jikes Compiler
  4. // License Agreement available at the following URL:
  5. // http://www.ibm.com/research/jikes.
  6. // Copyright (C) 1996, 1998, International Business Machines Corporation
  7. // and others.  All Rights Reserved.
  8. // You must accept the terms of that agreement to use this software.
  9. //
  10. #include "config.h"
  11. #include "ast.h"
  12. #include <iostream.h>
  13. #include <fstream.h>
  14. #ifdef TEST
  15.     bool Ast::debug_unparse = false;
  16. #endif
  17.  
  18.  
  19. #ifdef TEST
  20. // Special top-level form
  21. void AstCompilationUnit::Unparse(LexStream& lex_stream, char *directory)
  22. {
  23.     char *in_file_name = lex_stream.FileName();
  24.     // char *suffix = ".unparse";
  25.     char *suffix = "";
  26.     char *out_file_name = ::strcat3(directory, in_file_name, suffix);
  27.     // Create the directory if necessary
  28.     for (int i=strlen(out_file_name); i>=0; i--) {
  29.        if (out_file_name[i] == U_SLASH) {
  30.            out_file_name[i] = U_NULL;
  31.            if (! ::SystemIsDirectory(out_file_name))
  32.            {
  33.                Ostream() << "making directory " << out_file_name << "\n";
  34.                ::SystemMkdirhier(out_file_name);
  35.            }
  36.            out_file_name[i] = U_SLASH;
  37.            break;
  38.        }
  39.     }
  40.     ofstream os_base(out_file_name);
  41.     if (!os_base)
  42.     {
  43.         Ostream() << "Cannot open output file " << out_file_name << "\n";
  44.         abort();
  45.     }
  46.     Ostream os(&os_base);
  47.     this -> Unparse(os, lex_stream);
  48.     delete[] out_file_name;
  49. }
  50.  
  51. void Ast::Unparse(Ostream& os, LexStream& lex_stream)
  52. {
  53.     if (debug_unparse)
  54.         os << "/*Ast:#" << this-> id << "*/";
  55.     os << "***** TO DO *****";
  56.     os << "#" << this -> id << " (Ast):  ";
  57.     os << "Node kind " << (int) kind << " does not contain an unparse routine\n";
  58.     if (debug_unparse)
  59.         os << "/*:Ast#" << this-> id << "*/";
  60. }
  61.  
  62. void AstBlock::Unparse(Ostream& os, LexStream& lex_stream)
  63. {
  64.     if (Ast::debug_unparse)
  65.         os << "/*AstBlock:#" << this-> id << "*/";
  66.     if (Ast::debug_unparse)
  67.         os << "/*no_braces:" << no_braces << "*/";
  68.     for (int il = 0; il < this -> NumLabels(); il++)
  69.     {
  70.         os << lex_stream.NameString(this -> Label(il)) << ": ";
  71.     }
  72.  
  73.     if (!no_braces)
  74.         os << "{\n";
  75.     for (int is = 0; is < this -> NumStatements(); is++)
  76.     {
  77.         this -> Statement(is) -> Unparse(os, lex_stream);
  78.     }
  79.     if (!no_braces)
  80.         os << "}\n";
  81.     if (Ast::debug_unparse)
  82.         os << "/*:AstBlock#" << this-> id << "*/";
  83. }
  84.  
  85. void AstPrimitiveType::Unparse(Ostream& os, LexStream& lex_stream)
  86. {
  87.     if (Ast::debug_unparse)
  88.         os << "/*AstPrimitiveType:#" << this-> id << "*/";
  89.     os << lex_stream.NameString(primitive_kind_token);
  90.     if (Ast::debug_unparse)
  91.         os << "/*:AstPrimitiveType#" << this-> id << "*/";
  92. }
  93.  
  94. void AstArrayType::Unparse(Ostream& os, LexStream& lex_stream)
  95. {
  96.     if (Ast::debug_unparse)
  97.         os << "/*AstArrayType:#" << this-> id << "*/";
  98.     type -> Unparse(os, lex_stream);
  99.     for (int i = 0; i < this -> NumBrackets(); i++)
  100.         os << "[]";
  101.     if (Ast::debug_unparse)
  102.         os << "/*:AstArrayType#" << this-> id << "*/";
  103. }
  104.  
  105. void AstSimpleName::Unparse(Ostream& os, LexStream& lex_stream)
  106. {
  107.     if (Ast::debug_unparse)
  108.         os << "/*AstSimpleName:#" << this-> id << "*/";
  109.     os << lex_stream.NameString(identifier_token);
  110.     if (Ast::debug_unparse)
  111.         os << "/*:AstSimpleName#" << this-> id << "*/";
  112. }
  113.  
  114. void AstPackageDeclaration::Unparse(Ostream& os, LexStream& lex_stream)
  115. {
  116.     if (Ast::debug_unparse)
  117.         os << "/*AstPackageDeclaration:#" << this-> id << "*/";
  118.     os << lex_stream.NameString(package_token);
  119.     os << " ";
  120.     name -> Unparse(os, lex_stream);
  121.     os << ";\n";
  122.     if (Ast::debug_unparse)
  123.         os << "/*:AstPackageDeclaration#" << this-> id << "*/";
  124. }
  125.  
  126. void AstImportDeclaration::Unparse(Ostream& os, LexStream& lex_stream)
  127. {
  128.     if (Ast::debug_unparse)
  129.         os << "/*AstImportDeclaration:#" << this-> id << "*/";
  130.     os << lex_stream.NameString(import_token);
  131.     os << " ";
  132.     name -> Unparse(os, lex_stream);
  133.     os << (star_token_opt ? "." : "");
  134.     if (star_token_opt)
  135.         os << lex_stream.NameString(star_token_opt);
  136.     os << ";\n";
  137.     if (Ast::debug_unparse)
  138.         os << "/*:AstImportDeclaration#" << this-> id << "*/";
  139. }
  140.  
  141. void AstCompilationUnit::Unparse(Ostream& os, LexStream& lex_stream)
  142. {
  143.     if (Ast::debug_unparse) os << "/*AstCompilationUnit:#" << this-> id << "*/";
  144.     // The file is
  145.     // os << lex_stream.FileName();
  146.     if (package_declaration_opt)
  147.         package_declaration_opt -> Unparse(os, lex_stream);
  148.     for (int m = 0; m < this -> NumImportDeclarations(); m++)
  149.         this -> ImportDeclaration(m) -> Unparse(os, lex_stream);
  150.     for (int n = 0; n < this -> NumTypeDeclarations(); n++)
  151.         this -> TypeDeclaration(n) -> Unparse(os, lex_stream);
  152.     if (Ast::debug_unparse)
  153.         os << "/*:AstCompilationUnit#" << this-> id << "*/";
  154. }
  155.  
  156. void AstModifier::Unparse(Ostream& os, LexStream& lex_stream)
  157. {
  158.     if (Ast::debug_unparse)
  159.         os << "/*AstModifier:#" << this-> id << "*/";
  160.     os << lex_stream.NameString(modifier_kind_token);
  161.     os << " ";
  162.     if (Ast::debug_unparse)
  163.        os << "/*:AstModifier#" << this-> id << "*/";
  164. }
  165.  
  166. void AstEmptyDeclaration::Unparse(Ostream& os, LexStream& lex_stream)
  167. {
  168.     if (Ast::debug_unparse)
  169.        os << "/*AstEmptyDeclaration:#" << this-> id << "*/";
  170.     os << lex_stream.NameString(semicolon_token);
  171.     os << "\n";
  172.     if (Ast::debug_unparse)
  173.     os << "/*:AstEmptyDeclaration#" << this-> id << "*/";
  174. }
  175.  
  176. void AstClassBody::Unparse(Ostream& os, LexStream& lex_stream)
  177. {
  178.     if (Ast::debug_unparse)
  179.         os << "/*AstClassBody:#" << this-> id << "*/";
  180.     os << "{\n";
  181.     for (int k = 0; k < this -> NumClassBodyDeclarations(); k++)
  182.         this -> ClassBodyDeclaration(k) -> Unparse(os, lex_stream);
  183.     os << "}\n\n";
  184.     if (Ast::debug_unparse)
  185.         os << "/*:AstClassBody#" << this-> id << "*/";
  186. }
  187.  
  188. void AstClassDeclaration::Unparse(Ostream& os, LexStream& lex_stream)
  189. {
  190.     if (Ast::debug_unparse)
  191.         os << "/*AstClassDeclaration:#" << this-> id << "*/";
  192.     for (int i = 0; i < this -> NumClassModifiers(); i++)
  193.     {
  194.         os << lex_stream.NameString(this -> ClassModifier(i) -> modifier_kind_token);
  195.         os << " ";
  196.     }
  197.     os << lex_stream.NameString(class_token);
  198.     os << " ";
  199.     os << lex_stream.NameString(identifier_token);
  200.     os << " ";
  201.     if (super_opt)
  202.     {
  203.         os << "extends ";
  204.         super_opt -> Unparse(os, lex_stream);
  205.         os << " ";
  206.     }
  207.     if (NumInterfaces() > 0)
  208.     {
  209.         os << "implements ";
  210.         for (int j = 0; j < NumInterfaces(); j++)
  211.         {
  212.             if (j>0)
  213.                 os << ", ";
  214.             this -> Interface(j) -> Unparse(os, lex_stream);
  215.         }
  216.         os << " ";
  217.     }
  218.     // os << ") #" << class_body -> id << "\n";
  219.     class_body -> Unparse(os, lex_stream);
  220.     if (Ast::debug_unparse)
  221.         os << "/*:AstClassDeclaration#" << this-> id << "*/";
  222. }
  223.  
  224. void AstArrayInitializer::Unparse(Ostream& os, LexStream& lex_stream)
  225. {
  226.     if (Ast::debug_unparse)
  227.         os << "/*AstArrayInitializer:#" << this-> id << "*/";
  228.     os << "\n{ ";
  229.     for (int k = 0; k < NumVariableInitializers(); k++)
  230.     {
  231.         if (k>0)
  232.             os << ", ";
  233.         this -> VariableInitializer(k) -> Unparse(os, lex_stream);
  234.     }
  235.     os << " }";
  236.     if (Ast::debug_unparse)
  237.         os << "/*:AstArrayInitializer#" << this-> id << "*/";
  238. }
  239.  
  240. void AstBrackets::Unparse(Ostream& os, LexStream& lex_stream)
  241. {
  242.     if (Ast::debug_unparse)
  243.         os << "/*AstBrackets:#" << this-> id << "*/";
  244.     os << "[]";
  245.     if (Ast::debug_unparse)
  246.         os << "/*:AstBrackets#" << this-> id << "*/";
  247. }
  248.  
  249. void AstVariableDeclaratorId::Unparse(Ostream& os, LexStream& lex_stream)
  250. {
  251.     if (Ast::debug_unparse)
  252.         os << "/*AstVariableDeclaratorId:#" << this-> id << "*/";
  253.     os << lex_stream.NameString(identifier_token);
  254.     for (int i = 0; i < NumBrackets(); i++)
  255.         os << "[]";
  256.     if (Ast::debug_unparse)
  257.         os << "/*:AstVariableDeclaratorId#" << this-> id << "*/";
  258. }
  259.  
  260. void AstVariableDeclarator::Unparse(Ostream& os, LexStream& lex_stream)
  261. {
  262.     if (Ast::debug_unparse)
  263.         os << "/*AstVariableDeclarator:#" << this-> id << "*/";
  264.     variable_declarator_name -> Unparse(os, lex_stream);
  265.     if (variable_initializer_opt)
  266.     {
  267.         os << " = ";
  268.         variable_initializer_opt -> Unparse(os, lex_stream);
  269.     }
  270.     if (Ast::debug_unparse)
  271.         os << "/*:AstVariableDeclarator#" << this-> id << "*/";
  272. }
  273.  
  274. void AstFieldDeclaration::Unparse(Ostream& os, LexStream& lex_stream)
  275. {
  276.     if (Ast::debug_unparse)
  277.         os << "/*AstFieldDeclaration:#" << this-> id << "*/";
  278.     for (int i = 0; i < this -> NumVariableModifiers(); i++)
  279.     {
  280.         os << lex_stream.NameString(this -> VariableModifier(i) -> modifier_kind_token);
  281.         os << " ";
  282.     }
  283.     type -> Unparse(os, lex_stream);
  284.     os << " ";
  285.     for (int k = 0; k < this -> NumVariableDeclarators(); k++)
  286.     {
  287.         if (k>0)
  288.             os << " ,";
  289.         this -> VariableDeclarator(k) -> Unparse(os, lex_stream);
  290.     }
  291.     os << ";\n";
  292.     if (Ast::debug_unparse)
  293.         os << "/*:AstFieldDeclaration#" << this-> id << "*/";
  294. }
  295.  
  296. void AstFormalParameter::Unparse(Ostream& os, LexStream& lex_stream)
  297. {
  298.     if (Ast::debug_unparse)
  299.         os << "/*AstFormalParameter:#" << this-> id << "*/";
  300.     for (int i = 0; i < this -> NumParameterModifiers(); i++)
  301.     {
  302.         os << lex_stream.NameString(this -> ParameterModifier(i) -> modifier_kind_token);
  303.         os << " ";
  304.     }
  305.     type -> Unparse(os, lex_stream);
  306.     os << " ";
  307.     formal_declarator -> Unparse(os, lex_stream);
  308.     if (Ast::debug_unparse)
  309.         os << "/*:AstFormalParameter#" << this-> id << "*/";
  310. }
  311.  
  312. void AstMethodDeclarator::Unparse(Ostream& os, LexStream& lex_stream)
  313. {
  314.     if (Ast::debug_unparse)
  315.         os << "/*AstMethodDeclarator:#" << this-> id << "*/";
  316.     os << lex_stream.NameString(identifier_token);
  317.     os << " (";
  318.     for (int k = 0; k < this -> NumFormalParameters(); k++)
  319.     {
  320.         if (k>0)
  321.             os << ", ";
  322.         this -> FormalParameter(k) -> Unparse(os, lex_stream);
  323.     }
  324.     os << ") ";
  325.     for (int i = 0; i < NumBrackets(); i++)
  326.         os << "[]";
  327.     if (Ast::debug_unparse)
  328.         os << "/*:AstMethodDeclarator#" << this-> id << "*/";
  329. }
  330.  
  331. void AstMethodDeclaration::Unparse(Ostream& os, LexStream& lex_stream)
  332. {
  333.     if (Ast::debug_unparse)
  334.         os << "/*AstMethodDeclaration:#" << this-> id << "*/";
  335.     for (int i = 0; i < this -> NumMethodModifiers(); i++)
  336.     {
  337.         os << lex_stream.NameString(this -> MethodModifier(i) -> modifier_kind_token);
  338.         os << " ";
  339.     }
  340.     type -> Unparse(os, lex_stream);
  341.     os << " ";
  342.     method_declarator -> Unparse(os, lex_stream);
  343.     if (NumThrows() > 0)
  344.     {
  345.         os << " throws ";
  346.         for (int k = 0; k < this -> NumThrows(); k++)
  347.         {
  348.             if (k>0)
  349.                 os << ", ";
  350.             this -> Throw(k) -> Unparse(os, lex_stream);
  351.         }
  352.     }
  353.     method_body -> Unparse(os, lex_stream);
  354.     if (Ast::debug_unparse)
  355.         os << "/*:AstMethodDeclaration#" << this-> id << "*/";
  356. }
  357.  
  358. void AstStaticInitializer::Unparse(Ostream& os, LexStream& lex_stream)
  359. {
  360.     if (Ast::debug_unparse)
  361.         os << "/*AstStaticInitializer:#" << this-> id << "*/";
  362.     os << lex_stream.NameString(static_token);
  363.     block -> Unparse(os, lex_stream);
  364.     if (Ast::debug_unparse)
  365.         os << "/*:AstStaticInitializer#" << this-> id << "*/";
  366. }
  367.  
  368. void AstThisCall::Unparse(Ostream& os, LexStream& lex_stream)
  369. {
  370.     if (Ast::debug_unparse)
  371.         os << "/*AstThisCall:#" << this-> id << "*/";
  372.     os << lex_stream.NameString(this_token);
  373.     os << " (";
  374.     for (int i = 0; i < this -> NumArguments(); i++)
  375.     {
  376.         if (i>0)
  377.             os << ", ";
  378.         this -> Argument(i) -> Unparse(os, lex_stream);
  379.     }
  380.     os << ");\n";
  381.     if (Ast::debug_unparse)
  382.         os << "/*:AstThisCall#" << this-> id << "*/";
  383. }
  384.  
  385. void AstSuperCall::Unparse(Ostream& os, LexStream& lex_stream)
  386. {
  387.     if (Ast::debug_unparse)
  388.         os << "/*AstSuperCall:#" << this-> id << "*/";
  389.     if (wcscmp(lex_stream.NameString(super_token), L"super") == 0)
  390.     {
  391.         if (base_opt)
  392.         {
  393.             base_opt -> Unparse(os, lex_stream);
  394.             os << lex_stream.NameString(dot_token_opt);
  395.         }
  396.         os << lex_stream.NameString(super_token);
  397.         os << lex_stream.NameString(left_parenthesis_token);
  398.         for (int j = 0; j < NumArguments(); j++)
  399.         {
  400.             if (j>0)
  401.                 os << ", ";
  402.             this -> Argument(j) -> Unparse(os, lex_stream);
  403.         }
  404.         os << lex_stream.NameString(right_parenthesis_token);
  405.         os << lex_stream.NameString(semicolon_token);
  406.         os << "\n";
  407.     }
  408.     if (Ast::debug_unparse)
  409.          os << "/*:AstSuperCall#" << this-> id << "*/";
  410. }
  411.  
  412. void AstConstructorBlock::Unparse(Ostream& os, LexStream& lex_stream)
  413. {
  414.     if (Ast::debug_unparse)
  415.         os << "/*AstConstructorBlock:#" << this-> id << "*/";
  416.     if (explicit_constructor_invocation_opt)
  417.     {
  418.         os << "{\n";
  419.         explicit_constructor_invocation_opt -> Unparse(os, lex_stream);
  420.         // os << ";\n";
  421.     }
  422.     block -> Unparse(os, lex_stream);
  423.     if (explicit_constructor_invocation_opt)
  424.         os << "}\n";
  425.     if (Ast::debug_unparse)
  426.         os << "/*:AstConstructorBlock#" << this-> id << "*/";
  427. }
  428.  
  429. void AstConstructorDeclaration::Unparse(Ostream& os, LexStream& lex_stream)
  430. {
  431.     if (Ast::debug_unparse)
  432.         os << "/*AstConstructorDeclaration:#" << this-> id << "*/";
  433.     for (int i = 0; i < this -> NumConstructorModifiers(); i++)
  434.     {
  435.         os << lex_stream.NameString(this -> ConstructorModifier(i) -> modifier_kind_token);
  436.         os << " ";
  437.     }
  438.     constructor_declarator -> Unparse(os, lex_stream);
  439.     if (NumThrows() > 0)
  440.     {
  441.         os << " throws ";
  442.         for (int k = 0; k < this -> NumThrows(); k++)
  443.         {
  444.             if (k>0) os << ", ";
  445.             this -> Throw(k) -> Unparse(os, lex_stream);
  446.         }
  447.     }
  448.     constructor_body -> Unparse(os, lex_stream);
  449.     if (Ast::debug_unparse)
  450.         os << "/*:AstConstructorDeclaration#" << this-> id << "*/";
  451. }
  452.  
  453. void AstInterfaceDeclaration::Unparse(Ostream& os, LexStream& lex_stream)
  454. {
  455.     if (Ast::debug_unparse)
  456.         os << "/*AstInterfaceDeclaration:#" << this-> id << "*/";
  457.     for (int i = 0; i < this -> NumInterfaceModifiers(); i++)
  458.     {
  459.         os << lex_stream.NameString(this -> InterfaceModifier(i) -> modifier_kind_token);
  460.         os << " ";
  461.     }
  462.     os << lex_stream.NameString(interface_token);
  463.     os << " ";
  464.     os << lex_stream.NameString(identifier_token);
  465.     if (NumExtendsInterfaces() > 0)
  466.     {
  467.         os << " extends ";
  468.         for (int j = 0; j < NumExtendsInterfaces(); j++)
  469.         {
  470.             if (j>0)
  471.                 os << ", ";
  472.             this -> ExtendsInterface(j) -> Unparse(os, lex_stream);
  473.         }
  474.     }
  475.     os << " {\n";
  476.     for (int k = 0; k < NumInterfaceMemberDeclarations(); k++)
  477.     {
  478.         this -> InterfaceMemberDeclaration(k) -> Unparse(os, lex_stream);
  479.         os << "\n";
  480.     }
  481.     os << "}\n";
  482.     if (Ast::debug_unparse)
  483.         os << "/*:AstInterfaceDeclaration#" << this-> id << "*/";
  484. }
  485.  
  486. void AstLocalVariableDeclarationStatement::Unparse(Ostream& os, LexStream& lex_stream)
  487. {
  488.     if (Ast::debug_unparse)
  489.         os << "/*AstLocalVariableDeclarationStatement:#" << this-> id << "*/";
  490.     for (int i = 0; i < this -> NumLocalModifiers(); i++)
  491.     {
  492.         os << lex_stream.NameString(this -> LocalModifier(i) -> modifier_kind_token);
  493.         os << " ";
  494.     }
  495.     type -> Unparse(os, lex_stream);
  496.     os << " ";
  497.     for (int k = 0; k < this -> NumVariableDeclarators(); k++)
  498.     {
  499.         if (k>0)
  500.             os << ",";
  501.         this -> VariableDeclarator(k) -> Unparse(os, lex_stream);
  502.     }
  503.     if (semicolon_token_opt)
  504.         os << ";\n";
  505.     if (Ast::debug_unparse)
  506.         os << "/*:AstLocalVariableDeclarationStatement#" << this-> id << "*/";
  507. }
  508.  
  509. void AstIfStatement::Unparse(Ostream& os, LexStream& lex_stream)
  510. {
  511.     if (Ast::debug_unparse)
  512.         os << "/*AstIfStatement:#" << this-> id << "*/";
  513.     os << lex_stream.NameString(if_token);
  514.     AstParenthesizedExpression *parenth = expression -> ParenthesizedExpressionCast();
  515.     if (!parenth)
  516.         os << "(";
  517.     expression -> Unparse(os, lex_stream);
  518.     if (!parenth)
  519.         os << ")";
  520.     os << "\n";
  521.     true_statement -> Unparse(os, lex_stream);
  522.     if (false_statement_opt)
  523.     {
  524.         os << "else\n";
  525.         false_statement_opt -> Unparse(os, lex_stream);
  526.     }
  527.     os << "\n";
  528.     if (Ast::debug_unparse)
  529.         os << "/*:AstIfStatement#" << this-> id << "*/";
  530. }
  531.  
  532. void AstEmptyStatement::Unparse(Ostream& os, LexStream& lex_stream)
  533. {
  534.     if (Ast::debug_unparse)
  535.         os << "/*AstEmptyStatement:#" << this-> id << "*/";
  536.     os << lex_stream.NameString(semicolon_token);
  537.     os << "\n";
  538.     if (Ast::debug_unparse)
  539.         os << "/*:AstEmptyStatement#" << this-> id << "*/";
  540. }
  541.  
  542. void AstExpressionStatement::Unparse(Ostream& os, LexStream& lex_stream)
  543. {
  544.     if (Ast::debug_unparse)
  545.         os << "/*AstExpressionStatement:#" << this-> id << "*/";
  546.     expression -> Unparse(os, lex_stream);
  547.     if (semicolon_token_opt)
  548.         os << ";\n";
  549.     if (Ast::debug_unparse)
  550.         os << "/*:AstExpressionStatement#" << this-> id << "*/";
  551. }
  552.  
  553. void AstCaseLabel::Unparse(Ostream& os, LexStream& lex_stream)
  554. {
  555.     if (Ast::debug_unparse)
  556.         os << "/*AstCaseLabel:#" << this-> id << "*/";
  557.     os << lex_stream.NameString(case_token);
  558.     os << " ";
  559.     expression -> Unparse(os, lex_stream);
  560.     os << ":\n";
  561.     if (Ast::debug_unparse)
  562.         os << "/*:AstCaseLabel#" << this-> id << "*/";
  563. }
  564.  
  565. void AstDefaultLabel::Unparse(Ostream& os, LexStream& lex_stream)
  566. {
  567.     if (Ast::debug_unparse)
  568.         os << "/*AstDefaultLabel:#" << this-> id << "*/";
  569.     os << lex_stream.NameString(default_token);
  570.     os << ":\n";
  571.     if (Ast::debug_unparse)
  572.         os << "/*:AstDefaultLabel#" << this-> id << "*/";
  573. }
  574.  
  575. void AstSwitchBlockStatement::Unparse(Ostream& os, LexStream& lex_stream)
  576. {
  577.     if (Ast::debug_unparse)
  578.         os << "/*AstSwitchBlockStatement:#" << this-> id << "*/";
  579.     for (int j = 0; j < NumSwitchLabels(); j++)
  580.         this -> SwitchLabel(j) -> Unparse(os, lex_stream);
  581.     for (int l = 0; l < NumStatements(); l++)
  582.         this -> Statement(l) -> Unparse(os, lex_stream);
  583.     if (Ast::debug_unparse)
  584.         os << "/*:AstSwitchBlockStatement#" << this-> id << "*/";
  585. }
  586.  
  587. void AstSwitchStatement::Unparse(Ostream& os, LexStream& lex_stream)
  588. {
  589.     if (Ast::debug_unparse)
  590.         os << "/*AstSwitchStatement:#" << this-> id << "*/";
  591.   // What about the label_opt??
  592.     os << lex_stream.NameString(switch_token);
  593.     AstParenthesizedExpression *parenth = expression -> ParenthesizedExpressionCast();
  594.     if (!parenth)
  595.         os << "(";
  596.     expression -> Unparse(os, lex_stream);
  597.     if (!parenth)
  598.         os << ")";
  599.     // I think that switch_block will output its own braces.
  600.     // os << "{\n";
  601.     switch_block -> Unparse(os, lex_stream);
  602.     // what about switch_labels_opt?
  603.     // os << "}\n";
  604.     if (Ast::debug_unparse)
  605.         os << "/*:AstSwitchStatement#" << this-> id << "*/";
  606. }
  607.  
  608. void AstWhileStatement::Unparse(Ostream& os, LexStream& lex_stream)
  609. {
  610.     if (Ast::debug_unparse)
  611.         os << "/*AstWhileStatement:#" << this-> id << "*/";
  612.     os << lex_stream.NameString(while_token);
  613.     // What about Label_opt?
  614.     os << " ";
  615.     AstParenthesizedExpression *parenth = expression -> ParenthesizedExpressionCast();
  616.     if (!parenth)
  617.         os << "(";
  618.     expression -> Unparse(os, lex_stream);
  619.     if (!parenth)
  620.         os << ")";
  621.     os << "\n";
  622.     statement -> Unparse(os, lex_stream);
  623.     if (Ast::debug_unparse)
  624.         os << "/*:AstWhileStatement#" << this-> id << "*/";
  625. }
  626.  
  627. void AstDoStatement::Unparse(Ostream& os, LexStream& lex_stream)
  628. {
  629.     if (Ast::debug_unparse)
  630.         os << "/*AstDoStatement:#" << this-> id << "*/";
  631.     os << lex_stream.NameString(do_token);
  632.     os << "\n";
  633.     statement -> Unparse(os, lex_stream);
  634.     os << lex_stream.NameString(while_token);
  635.     AstParenthesizedExpression *parenth = expression -> ParenthesizedExpressionCast();
  636.     if (!parenth)
  637.         os << "(";
  638.     expression -> Unparse(os, lex_stream);
  639.     if (!parenth)
  640.         os << ")";
  641.     os << lex_stream.NameString(semicolon_token);
  642.     os << "\n";
  643.     if (Ast::debug_unparse)
  644.         os << "/*:AstDoStatement#" << this-> id << "*/";
  645. }
  646.  
  647. void AstForStatement::Unparse(Ostream& os, LexStream& lex_stream)
  648. {
  649.     if (Ast::debug_unparse)
  650.         os << "/*AstForStatement:#" << this-> id << "*/";
  651.     os << lex_stream.NameString(for_token);
  652.     os << " (";
  653.     for (int i = 0; i < this -> NumForInitStatements(); i++)
  654.     {
  655.         if (i>0)
  656.             os << ", ";
  657.         this -> ForInitStatement(i) -> Unparse(os, lex_stream);
  658.     }
  659.     os << "; ";
  660.     if (end_expression_opt)
  661.         end_expression_opt -> Unparse(os, lex_stream);
  662.     os << "; ";
  663.     for (int k = 0; k < this -> NumForUpdateStatements(); k++)
  664.     {
  665.         if (k>0)
  666.             os << ", ";
  667.         this -> ForUpdateStatement(k) -> Unparse(os, lex_stream);
  668.     }
  669.     os << ")\n";
  670.     statement -> Unparse(os, lex_stream);
  671.     if (Ast::debug_unparse)
  672.         os << "/*:AstForStatement#" << this-> id << "*/";
  673. }
  674.  
  675. void AstBreakStatement::Unparse(Ostream& os, LexStream& lex_stream)
  676. {
  677.     if (Ast::debug_unparse)
  678.         os << "/*AstBreakStatement:#" << this-> id << "*/";
  679.     os << lex_stream.NameString(break_token);
  680.     if (identifier_token_opt)
  681.     {
  682.         os << " ";
  683.         os << lex_stream.NameString(identifier_token_opt);
  684.     }
  685.     os << ";\n";
  686.     if (Ast::debug_unparse)
  687.         os << "/*:AstBreakStatement#" << this-> id << "*/";
  688. }
  689.  
  690. void AstContinueStatement::Unparse(Ostream& os, LexStream& lex_stream)
  691. {
  692.     if (Ast::debug_unparse)
  693.         os << "/*AstContinueStatement:#" << this-> id << "*/";
  694.     os << lex_stream.NameString(continue_token);
  695.     if (identifier_token_opt)
  696.     {
  697.         os << " ";
  698.         os << lex_stream.NameString(identifier_token_opt);
  699.     }
  700.     os << ";\n";
  701.     if (Ast::debug_unparse)
  702.         os << "/*:AstContinueStatement#" << this-> id << "*/";
  703. }
  704.  
  705. void AstReturnStatement::Unparse(Ostream& os, LexStream& lex_stream)
  706. {
  707.     if (Ast::debug_unparse)
  708.         os << "/*AstReturnStatement:#" << this-> id << "*/";
  709.     // Do NOT use this; when the return statement is not literally
  710.     // present in the source, the return_token points at the next "}".
  711.     // os << lex_stream.NameString(return_token);
  712.     os << "return";
  713.     if (expression_opt)
  714.     {
  715.         os << " ";
  716.         expression_opt -> Unparse(os, lex_stream);
  717.     }
  718.     os << ";\n";
  719.     if (Ast::debug_unparse)
  720.         os << "/*:AstReturnStatement#" << this-> id << "*/";
  721. }
  722.  
  723. void AstThrowStatement::Unparse(Ostream& os, LexStream& lex_stream)
  724. {
  725.     if (Ast::debug_unparse)
  726.         os << "/*AstThrowStatement:#" << this-> id << "*/";
  727.     os << lex_stream.NameString(throw_token);
  728.     os << " ";
  729.     expression -> Unparse(os, lex_stream);
  730.     os << ";\n";
  731.     if (Ast::debug_unparse)
  732.         os << "/*:AstThrowStatement#" << this-> id << "*/";
  733. }
  734.  
  735. void AstSynchronizedStatement::Unparse(Ostream& os, LexStream& lex_stream)
  736. {
  737.     if (Ast::debug_unparse)
  738.         os << "/*AstSynchronizedStatement:#" << this-> id << "*/";
  739.     os << lex_stream.NameString(synchronized_token);
  740.     os << " ";
  741.     AstParenthesizedExpression *parenth = expression -> ParenthesizedExpressionCast();
  742.     if (!parenth)
  743.         os << "(";
  744.     expression -> Unparse(os, lex_stream);
  745.     if (!parenth)
  746.         os << ")";
  747.     os << "\n";
  748.     block -> Unparse(os, lex_stream);
  749.     if (Ast::debug_unparse)
  750.         os << "/*:AstSynchronizedStatement#" << this-> id << "*/";
  751. }
  752.  
  753. void AstCatchClause::Unparse(Ostream& os, LexStream& lex_stream)
  754. {
  755.     if (Ast::debug_unparse)
  756.         os << "/*AstCatchClause:#" << this-> id << "*/";
  757.     os << lex_stream.NameString(catch_token);
  758.     os << " (";
  759.     formal_parameter -> Unparse(os, lex_stream);
  760.     os << ")\n";
  761.     block -> Unparse(os, lex_stream);
  762.     if (Ast::debug_unparse)
  763.         os << "/*:AstCatchClause#" << this-> id << "*/";
  764. }
  765.  
  766. void AstFinallyClause::Unparse(Ostream& os, LexStream& lex_stream)
  767. {
  768.     if (Ast::debug_unparse)
  769.         os << "/*AstFinallyClause:#" << this-> id << "*/";
  770.     os << lex_stream.NameString(finally_token);
  771.     os << "\n";
  772.     block -> Unparse(os, lex_stream);
  773.     if (Ast::debug_unparse) os << "/*:AstFinallyClause#" << this-> id << "*/";
  774. }
  775.  
  776. void AstTryStatement::Unparse(Ostream& os, LexStream& lex_stream)
  777. {
  778.     if (Ast::debug_unparse)
  779.         os << "/*AstTryStatement:#" << this-> id << "*/";
  780.     os << lex_stream.NameString(try_token);
  781.     os << "\n";
  782.     block -> Unparse(os, lex_stream);
  783.     for (int k = 0; k < this -> NumCatchClauses(); k++)
  784.         this -> CatchClause(k) -> Unparse(os, lex_stream);
  785.     if (finally_clause_opt)
  786.         finally_clause_opt -> Unparse(os, lex_stream);
  787.     if (Ast::debug_unparse)
  788.         os << "/*:AstTryStatement#" << this-> id << "*/";
  789. }
  790.  
  791. void AstIntegerLiteral::Unparse(Ostream& os, LexStream& lex_stream)
  792. {
  793.     if (Ast::debug_unparse)
  794.         os << "/*AstIntegerLiteral:#" << this-> id << "*/";
  795.     os << lex_stream.NameString(integer_literal_token);
  796.     if (Ast::debug_unparse)
  797.         os << "/*:AstIntegerLiteral#" << this-> id << "*/";
  798. }
  799.  
  800. void AstLongLiteral::Unparse(Ostream& os, LexStream& lex_stream)
  801. {
  802.     if (Ast::debug_unparse)
  803.         os << "/*AstLongLiteral:#" << this-> id << "*/";
  804.     os << lex_stream.NameString(long_literal_token);
  805.     if (Ast::debug_unparse)
  806.         os << "/*:AstLongLiteral#" << this-> id << "*/";
  807. }
  808.  
  809. void AstFloatingPointLiteral::Unparse(Ostream& os, LexStream& lex_stream)
  810. {
  811.     if (Ast::debug_unparse)
  812.         os << "/*AstFloatingPointLiteral:#" << this-> id << "*/";
  813.     os << lex_stream.NameString(floating_point_literal_token);
  814.     if (Ast::debug_unparse)
  815.         os << "/*:AstFloatingPointLiteral#" << this-> id << "*/";
  816. }
  817.  
  818. void AstDoubleLiteral::Unparse(Ostream& os, LexStream& lex_stream)
  819. {
  820.     if (Ast::debug_unparse)
  821.         os << "/*AstDoubleLiteral:#" << this-> id << "*/";
  822.     os << lex_stream.NameString(double_literal_token);
  823.     if (Ast::debug_unparse)
  824.         os << "/*:AstDoubleLiteral#" << this-> id << "*/";
  825. }
  826.  
  827. void AstTrueLiteral::Unparse(Ostream& os, LexStream& lex_stream)
  828. {
  829.     if (Ast::debug_unparse)
  830.         os << "/*AstTrueLiteral:#" << this-> id << "*/";
  831.     os << lex_stream.NameString(true_literal_token);
  832.     if (Ast::debug_unparse)
  833.         os << "/*:AstTrueLiteral#" << this-> id << "*/";
  834. }
  835.  
  836. void AstFalseLiteral::Unparse(Ostream& os, LexStream& lex_stream)
  837. {
  838.     if (Ast::debug_unparse)
  839.         os << "/*AstFalseLiteral:#" << this-> id << "*/";
  840.     os << lex_stream.NameString(false_literal_token);
  841.     if (Ast::debug_unparse)
  842.         os << "/*:AstFalseLiteral#" << this-> id << "*/";
  843. }
  844.  
  845. void AstStringLiteral::Unparse(Ostream& os, LexStream& lex_stream)
  846. {
  847.     if (Ast::debug_unparse)
  848.         os << "/*AstStringLiteral:#" << this-> id << "*/";
  849.     {
  850.         bool old_expand = os.ExpandWchar();
  851.         os.SetExpandWchar(true);
  852.         os << lex_stream.NameString(string_literal_token), lex_stream.NameStringLength(string_literal_token);
  853.         os.SetExpandWchar(old_expand);
  854.     }
  855.     if (Ast::debug_unparse)
  856.         os << "/*:AstStringLiteral#" << this-> id << "*/";
  857. }
  858.  
  859. void AstCharacterLiteral::Unparse(Ostream& os, LexStream& lex_stream)
  860. {
  861.     if (Ast::debug_unparse)
  862.         os << "/*AstCharacterLiteral:#" << this-> id << "*/";
  863.     {
  864.         bool old_expand = os.ExpandWchar();
  865.         os.SetExpandWchar(true);
  866.         os << lex_stream.NameString(character_literal_token), lex_stream.NameStringLength(character_literal_token);
  867.         os.SetExpandWchar(old_expand);
  868.     }
  869.     if (Ast::debug_unparse)
  870.         os << "/*:AstCharacterLiteral#" << this-> id << "*/";
  871. }
  872.  
  873. void AstNullLiteral::Unparse(Ostream& os, LexStream& lex_stream)
  874. {
  875.     if (Ast::debug_unparse)
  876.         os << "/*AstNullLiteral:#" << this-> id << "*/";
  877.     os << lex_stream.NameString(null_token);
  878.     if (Ast::debug_unparse)
  879.         os << "/*:AstNullLiteral#" << this-> id << "*/";
  880. }
  881.  
  882. void AstThisExpression::Unparse(Ostream& os, LexStream& lex_stream)
  883. {
  884.     if (Ast::debug_unparse)
  885.         os << "/*AstThisExpression:#" << this-> id << "*/";
  886.     os << lex_stream.NameString(this_token);
  887.     if (Ast::debug_unparse)
  888.         os << "/*:AstThisExpression#" << this-> id << "*/";
  889. }
  890.  
  891. void AstSuperExpression::Unparse(Ostream& os, LexStream& lex_stream)
  892. {
  893.     if (Ast::debug_unparse)
  894.         os << "/*AstSuperExpression:#" << this-> id << "*/";
  895.     os << lex_stream.NameString(super_token);
  896.     if (Ast::debug_unparse)
  897.         os << "/*:AstSuperExpression#" << this-> id << "*/";
  898. }
  899.  
  900. void AstParenthesizedExpression::Unparse(Ostream& os, LexStream& lex_stream)
  901. {
  902.     if (Ast::debug_unparse)
  903.         os << "/*AstParenthesizedExpression:#" << this-> id << "*/";
  904.     os << lex_stream.NameString(left_parenthesis_token);
  905.     expression -> Unparse(os, lex_stream);
  906.     os << lex_stream.NameString(right_parenthesis_token);
  907.     if (Ast::debug_unparse)
  908.         os << "/*:AstParenthesizedExpression#" << this-> id << "*/";
  909. }
  910.  
  911. void AstTypeExpression::Unparse(Ostream& os, LexStream& lex_stream)
  912. {
  913.     if (Ast::debug_unparse)
  914.         os << "/*AstTypeExpression:#" << this-> id << "*/";
  915.     type -> Unparse(os, lex_stream);
  916.     if (Ast::debug_unparse)
  917.         os << "/*:AstTypeExpression#" << this-> id << "*/";
  918. }
  919.  
  920. void AstClassInstanceCreationExpression::Unparse(Ostream& os, LexStream& lex_stream)
  921. {
  922.     if (Ast::debug_unparse)
  923.         os << "/*AstClassInstanceCreationExpression:#" << this-> id << "*/";
  924.     if (dot_token_opt /* base_opt - see ast.h for explanation */)
  925.         base_opt -> Unparse(os, lex_stream);
  926.     os << lex_stream.NameString(new_token);
  927.     os << " ";
  928.     class_type -> Unparse(os, lex_stream);
  929.     os << "( ";
  930.     for (int j = 0; j < NumArguments(); j++)
  931.     {
  932.         if (j>0)
  933.             os << ", ";
  934.         this -> Argument(j) -> Unparse(os, lex_stream);
  935.     }
  936.     os << " )";
  937.  
  938.     if (class_body_opt)
  939.         class_body_opt -> Unparse(os, lex_stream);
  940.     if (Ast::debug_unparse)
  941.         os << "/*:AstClassInstanceCreationExpression#" << this-> id << "*/";
  942. }
  943.  
  944. void AstDimExpr::Unparse(Ostream& os, LexStream& lex_stream)
  945. {
  946.     if (Ast::debug_unparse)
  947.         os << "/*AstDimExpr:#" << this-> id << "*/";
  948.     os << "[";
  949.     expression -> Unparse(os, lex_stream);
  950.     os << "]";
  951.     if (Ast::debug_unparse)
  952.         os << "/*:AstDimExpr#" << this-> id << "*/";
  953. }
  954.  
  955. void AstArrayCreationExpression::Unparse(Ostream& os, LexStream& lex_stream)
  956. {
  957.     if (Ast::debug_unparse)
  958.         os << "/*AstArrayCreationExpression:#" << this-> id << "*/";
  959.     os << lex_stream.NameString(new_token);
  960.     os << " ";
  961.     array_type -> Unparse(os, lex_stream);
  962.     for (int i = 0; i < NumDimExprs(); i++)
  963.         DimExpr(i) -> Unparse(os, lex_stream);
  964.     for (int k = 0; k < NumBrackets(); k++)
  965.        os << "[]";
  966.     if (array_initializer_opt)
  967.         array_initializer_opt -> Unparse(os, lex_stream);
  968.     if (Ast::debug_unparse)
  969.         os << "/*:AstArrayCreationExpression#" << this-> id << "*/";
  970. }
  971.  
  972. void AstFieldAccess::Unparse(Ostream& os, LexStream& lex_stream)
  973. {
  974.     if (Ast::debug_unparse)
  975.         os << "/*AstFieldAccess:#" << this-> id << "*/";
  976.     base -> Unparse(os, lex_stream);
  977.     os << lex_stream.NameString(dot_token);
  978.     os << lex_stream.NameString(identifier_token);
  979.     if (Ast::debug_unparse)
  980.         os << "/*:AstFieldAccess#" << this-> id << "*/";
  981. }
  982.  
  983. void AstMethodInvocation::Unparse(Ostream& os, LexStream& lex_stream)
  984. {
  985.     if (Ast::debug_unparse)
  986.         os << "/*AstMethodInvocation:#" << this-> id << "*/";
  987.     method -> Unparse(os, lex_stream);
  988.     os << "(";
  989.     for (int i = 0; i < this -> NumArguments(); i++)
  990.     {
  991.         if (i>0)
  992.             os << ", ";
  993.         this -> Argument(i) -> Unparse(os, lex_stream);
  994.     }
  995.     os << ")";
  996.     if (Ast::debug_unparse)
  997.         os << "/*:AstMethodInvocation#" << this-> id << "*/";
  998. }
  999.  
  1000. void AstArrayAccess::Unparse(Ostream& os, LexStream& lex_stream)
  1001. {
  1002.     if (Ast::debug_unparse)
  1003.         os << "/*AstArrayAccess:#" << this-> id << "*/";
  1004.     base -> Unparse(os, lex_stream);
  1005.     os << "[";
  1006.     expression -> Unparse(os, lex_stream);
  1007.     os << "]";
  1008.     if (Ast::debug_unparse)
  1009.         os << "/*:AstArrayAccess#" << this-> id << "*/";
  1010. }
  1011.  
  1012. void AstPostUnaryExpression::Unparse(Ostream& os, LexStream& lex_stream)
  1013. {
  1014.     if (Ast::debug_unparse)
  1015.         os << "/*AstPostUnaryExpression:#" << this-> id << "*/";
  1016.     expression -> Unparse(os, lex_stream);
  1017.     os << lex_stream.NameString(post_operator_token);
  1018.     if (Ast::debug_unparse)
  1019.         os << "/*:AstPostUnaryExpression#" << this-> id << "*/";
  1020. }
  1021.  
  1022. void AstPreUnaryExpression::Unparse(Ostream& os, LexStream& lex_stream)
  1023. {
  1024.     if (Ast::debug_unparse)
  1025.         os << "/*AstPreUnaryExpression:#" << this-> id << "*/";
  1026.     os << lex_stream.NameString(pre_operator_token);
  1027.     expression -> Unparse(os, lex_stream);
  1028.     if (Ast::debug_unparse)
  1029.         os << "/*:AstPreUnaryExpression#" << this-> id << "*/";
  1030. }
  1031.  
  1032. void AstCastExpression::Unparse(Ostream& os, LexStream& lex_stream)
  1033. {
  1034.     if (Ast::debug_unparse)
  1035.         os << "/*AstCastExpression:#" << this-> id << "*/";
  1036.     if (left_parenthesis_token_opt && type_opt)
  1037.     {
  1038.         os << "(";
  1039.         type_opt -> Unparse(os, lex_stream);
  1040.         for (int i = 0; i < NumBrackets(); i++)
  1041.             os << "[]";
  1042.         os << ")";
  1043.     }
  1044.  
  1045.     expression -> Unparse(os, lex_stream);
  1046.     if (Ast::debug_unparse)
  1047.         os << "/*:AstCastExpression#" << this-> id << "*/";
  1048. }
  1049.  
  1050. void AstBinaryExpression::Unparse(Ostream& os, LexStream& lex_stream)
  1051. {
  1052.     if (Ast::debug_unparse)
  1053.         os << "/*AstBinaryExpression:#" << this-> id << "*/";
  1054.     left_expression -> Unparse(os, lex_stream);
  1055.     os << " ";
  1056.     os << lex_stream.NameString(binary_operator_token);
  1057.     os << " ";
  1058.     right_expression -> Unparse(os, lex_stream);
  1059.     if (Ast::debug_unparse)
  1060.         os << "/*:AstBinaryExpression#" << this-> id << "*/";
  1061. }
  1062.  
  1063. void AstConditionalExpression::Unparse(Ostream& os, LexStream& lex_stream)
  1064. {
  1065.     if (Ast::debug_unparse)
  1066.         os << "/*AstConditionalExpression:#" << this-> id << "*/";
  1067.     test_expression -> Unparse(os, lex_stream);
  1068.     os << " ? ";
  1069.     true_expression -> Unparse(os, lex_stream);
  1070.     os << " : ";
  1071.     false_expression -> Unparse(os, lex_stream);
  1072.     if (Ast::debug_unparse)
  1073.         os << "/*:AstConditionalExpression#" << this-> id << "*/";
  1074. }
  1075.  
  1076. void AstAssignmentExpression::Unparse(Ostream& os, LexStream& lex_stream)
  1077. {
  1078.     if (Ast::debug_unparse)
  1079.         os << "/*AstAssignmentExpression:#" << this-> id << "*/";
  1080.     left_hand_side -> Unparse(os, lex_stream);
  1081.     os << " ";
  1082.     os << lex_stream.NameString(assignment_operator_token);
  1083.     os << " ";
  1084.     expression -> Unparse(os, lex_stream);
  1085.     if (Ast::debug_unparse)
  1086.         os << "/*:AstAssignmentExpression#" << this-> id << "*/";
  1087. }
  1088. #endif
  1089.